
package com.situ.yB2C.upfile.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.situ.yB2C.upfile.service.UpfileService;
import com.situ.yB2C.util.ContextUtil;



@Controller
@ResponseBody
public class UpfileController {
	private static final Logger LOG = LoggerFactory.getLogger(UpfileController.class );
	
	@Autowired
	private UpfileService upfileService;
	/**
	 *  #通用的上传文件功能
	 * @param multipartFile  上传的二进制文件
	 * @param fileKind  文件的类别 #1：用户头像 2：商品图片 3：
	 * @return
	 */
	@RequestMapping("/upfiles")
	public String doUpFile(MultipartFile partFile, Integer fileKind) {
		LOG.debug(partFile.toString());
		LOG.debug("fileKind="+fileKind);
		//得到项目的根路径 ,HttpServletRequest request
		//String realPath = request.getServletContext().getRealPath("/");
		//得到项目的根路径
		String realPath = ContextUtil.realPath;
		return upfileService.dofileUpload(partFile, fileKind, realPath);
	}
}







